<template>
 	<view>
		<!-- 搜索栏 -->
		<view class="search-box">
		<my-search></my-search>
	    </view>
 		<!-- 轮播图区域  -->
 		<swiper class="swiper" :indicator-dots="true" :autoplay="true" :duration="1000" :interval="3000"
 			:circular="true">
 			<swiper-item v-for="(item,index) in swiperdata" :key='index'>
 				<navigator :url="`/subpkg/goods-detail/goods-detail?goods_id=${item.goods_id}`" class="swiper-item">
 					<image :src="item.image_src"></image>
 				</navigator>
 			</swiper-item>
 		</swiper>
 		<!-- 分类导航区域 -->
 		<view class="nav-list">
 			<view class="list" v-for="(item,index) in catitems" :key='index' @click="navClickHandler(item,)">
 				<image :src="item.image_src"></image>
 			</view>
 		</view>
 		<!-- 楼层区域 -->
 		<view class="floor-list">
 			<view class="floor-item" v-for="(item,index) in floorList" :key='index'>
 				<image :src="item.floor_title.image_src" class="floor-title"></image>
 				<view class="floor-img-box">
 					<view class="left-img-box" @click="navigator_url(item.product_list[0].navigator_url)">
 						<image :src="item.product_list[0].image_src"
 							:style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
 					</view>
 					<view class="right-img-box">
 						<view class="right-img-box" v-for="(e,j) in item.product_list" :key='j' v-if="j!==0" @click="navigator_url(e.navigator_url)">
 							<image :src="e.image_src" mode="widthFix" :style="{width: e.image_width +'rpx'}"></image>
 						</view>
 					</view>
 				</view>
 			</view>
 		</view>
 	</view>
 </template>

 <script>
	 // 导入自己封装的 mixin 模块
	 import badgeMix from '@/mixins/tabbar-badge.js'
 	export default {
		  // 将 badgeMix 混入到当前的页面中进行使用
		 mixins: [badgeMix],
 		data() {
 			return {
 				//  轮播图的数据列表
 				swiperdata: [],
 				//  分类导航的数据列表
 				catitems: [],
 				//  楼层的数据列表
 				floorList: []
 			};
 		},
 		onLoad() {
 			// 在 onLoad 中调用获取数据的方法
 			this.getSwiperList()
 			this.getbtap()
 			this.getFloorList()
 		},
 		methods: {
 			// 获取轮播图数据
 			async getSwiperList() {
 				const {
 					data: res
 				} = await uni.$http.get('/api/public/v1/home/swiperdata')
				console.log(res,1)
 				if (res.meta.status !== 200) return uni.$showMsg()
 				this.swiperdata = res.message
 				// console.log(this.swiperdata)
 			},
 			// 获取分类导航数据
 			async getbtap() {
 				const {
 					data
 				} = await uni.$http.get('/api/public/v1/home/catitems')
 				this.catitems = data.message
 				// console.log(this.catitems)
 			},

 			// 定义获取楼层列表数据的方法
 			async getFloorList() {
 				const {
 					data: res
 				} = await uni.$http.get('/api/public/v1/home/floordata')
 				if (res.meta.status !== 200) return uni.$showMsg()
 				// this.floorList = res.message
 				this.floorList = res.message.map(item => {
 					return {
 						product_list: item.product_list.map(v => ({
 							...v,
 							navigator_url: v.navigator_url.split('?')[1]
 						})),
 						floor_title: item.floor_title
 					}

 				})
 				console.log(this.floorList)
 			},
 			//点击分类导航跳转对应页面
 			navClickHandler(item) {
 				if (item.name === "分类") {
 					uni.switchTab({
 						url: '/pages/cart/cart'
 					})
 				}

 			},
			navigator_url(res){
				uni.navigateTo({
					url:`/subpkg/goods-detail/goods-detail?${res}`
				})
			}
 		}
 	}
 </script>

 <style lang="scss">
 	.swiper {
 		height: 330rpx;

 		.swiper-item,
 		image {
 			height: 100%;
 			width: 100%;
 		}
 	}

 	.nav-list {
 		display: flex;
 		justify-content: space-around;
 		margin-top: 15px;

 		.list,
 		image {
 			width: 128rpx;
 			height: 140rpx;
 		}
 	}

 	.floor-title {
 		height: 60rpx;
 		width: 100%;
 		display: flex;

 	}

 	.floor-img-box {
 		display: flex;
 		padding-left: 10rpx;

 		.right-img-box {
 			display: flex;
 			flex-wrap: wrap;
 			justify-content: space-around;
 		}
 	}
	.search-box{
		// 设置定位效果为“吸顶”
		position: sticky;
		left: 0;
		top: 0;
		z-index: 100;
	}
 </style>
